﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using final_darskade.Models;
using final_darskade.Models.klassModel;
namespace final_darskade.Controllers
{
    public class klassManagementController : Controller
    {
        darskadeEntities de = new darskadeEntities();
        public KlassRepository repository;
        //public klassShowRepository klassShowRepository;
        public klassManagementController()
        //: this(new klassShowRepository())
        {
            repository = new KlassShowRepository();
        }
        //
        // GET: /KlassManagment/
        public klassManagementController(KlassRepository rep)
        {
            repository = rep;
        }


        public ActionResult klassShow()
        {
            //ViewData["Summaries"] = repository.GetFrontPageSummaries();
            //return View(ViewData["Summaries"]);
            return View(repository.GetFrontPageSummaries());
        }

        public ActionResult klassInsert()
        {
            ViewData["courseName"] = repository.GetCourseName();
            ViewData["professorName"] =repository.GetProfessorName();
            ViewData["timeid"] =repository.GetTimeid();
            return View("klassInsert");
        }

        [HttpPost]
        public ActionResult klassInsert([Bind(Include = "course_id,term,prof_id,time_id,start_exam_date_time,end_exam_date_time")]klass returningKlass)
        {
            //returningKlass.start_exam_date_time = (DateTime)returningKlass.start_exam_date_time;
            de.klasses.AddObject(returningKlass);
            de.SaveChanges();
            return RedirectToAction("klassShow");
        }


        //
        // GET: /KlassManagment/Edit/5

        public ActionResult klassEdit(int klassId)
        {
            klass selectedKlass = repository.findKlass(klassId);
            ViewData["courseName"] = repository.GetCourseName();
            ViewData["professorName"] = repository.GetProfessorName();
            ViewData["timeid"] = repository.GetTimeid();
            return View(selectedKlass);
        }

        //
        // POST: /KlassManagment/Edit/5

        [HttpPost]
        public ActionResult klassEdit(/*int id, */[Bind(Include = "id,course_id,term,prof_id,time_id,start_exam_date_time,end_exam_date_time")]klass returningKlass)
        {
            
            repository.updateKlass(returningKlass);
            return RedirectToAction("klassShow");
        }

        //
        // GET: /KlassManagment/Delete/5

        public ActionResult klassDelete(int klassId)
        {
            try
            {
                repository.deleteKlass(klassId);
            }
            catch (Exception ex)
            {
                // TODO: Must issue a proper message related to exception's message
                Response.Write(ex.Message);
            }
            return View("klassShow",repository.GetFrontPageSummaries());
        }
    }

    //class repository
    //{
        
    //}
}
